Current Location: Home> Function Categories> date_interval_format

date_interval_format

Alias ​​for DateInterval::format - Set the format of intervals
Name:date_interval_format
Category:Date and time
Programming Language:php
One-line Description:Format the time interval.

Definition and usage

date_interval_format() function is an alias for DateInterval::format() .

DateInterval::format() function is used to format the time interval.

Example

Calculate the interval between two day periods and format the interval:

 <?php
$date1 = date_create ( "1984-01-28" ) ;
$date2 = date_create ( "1980-10-15" ) ;
$diff = date_diff ( $date1 , $date2 ) ;

// %a Total number of days output
echo $diff -> format ( "Total days: %a." ) ;
?>

Try it yourself

grammar

 DateInterval :: format ( format ) ;
parameter describe
format

Required. Specified format. The format parameter string can use the following characters:

  • % - Literal %
  • Y - Year, at least 2 numbers, with leading zeros (e.g. 03)
  • y - year (for example 3)
  • M - Month, with leading zeros (for example, 06)
  • m - Month (for example, 6)
  • D - Day, with leading zeros (for example, 09)
  • d - day (e.g. 9)
  • a - The total number of days between two days, derived from date_diff()
  • H - hours, with leading zeros (for example, 08, 23)
  • h - hours (e.g. 8, 23)
  • I - points, with leading zeros (for example, 08, 23)
  • i - points (e.g. 8, 23)
  • S - seconds, with leading zeros (for example, 08, 23)
  • s - seconds (e.g. 8, 23)
  • R - when negative number is the symbol "-", when positive number is the symbol "+"
  • r - the symbol "-" when negative number, and empty when positive number

Comment: Each format string must be prefixed with the % symbol!

Similar Functions
Popular Articles